package com.changgou.search.controller;

import com.changgou.search.service.SkuInfoService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author: wzw
 * @Date: 2020/12/13 22:26
 * @version: 1.8
 */
@RestController
@RequestMapping("/search")
public class SkuInfoController {
    //注入service
    @Autowired
    private SkuInfoService skuInfoService;
    
    /**
     * @author wzw
     * 数据导入
     * @Date 22:28 2020/12/13
     * @param 
     * @return entity.Result
    **/
    @GetMapping("/import")
    public Result importData(){
        //实现功能
        skuInfoService.importSkuInfoToEs();
        //返回结果
        return new Result(true, StatusCode.OK, "数据导入成功");
    }


    /**
     * @author wzw
     * 检索
     * @Date 16:15 2020/12/14
     * @param searchMap
     * @return java.util.Map<java.lang.String,java.lang.Object>
    **/
    @GetMapping
    public Map<String, Object> search(@RequestParam(required = false) Map<String, String> searchMap) {
        //实现功能
        Map<String, Object> resultMap = skuInfoService.search(searchMap);
        //返回值
        return resultMap;
    }
}
